package at.cookieforensics;
import java.util.ArrayList;

import com.gargoylesoftware.htmlunit.util.Cookie;


/**
 * This class is a representation of all cookies separated by browsers
 * 
 * @author Martin Grottenthaler
 *
 */
public class AllCookies {
	/**
	 * list of chrome cookies
	 */
	private ArrayList<Cookie> chromeCookies;
	/**
	 * list of firefox cookies
	 */
	private ArrayList<Cookie> firefoxCookies;
	/**
	 * list of ie cookies
	 */
	private ArrayList<Cookie> ieCookies;
	
	/**
	 * Constructor which initializes all three lists
	 */
	public AllCookies() {
		chromeCookies = new ArrayList<Cookie>();
		firefoxCookies = new ArrayList<Cookie>();
		ieCookies = new ArrayList<Cookie>();
	}

	/**
	 * gets cookies for specified domain from specified browser
	 * @param browser 1 chrome, 2 firefox, 3 ie
	 * @param domain domain for which to get cookies
	 * @return arraylist of cookies
	 */
	public ArrayList<Cookie> getCookiesFromDomain(int browser, String domain) {
		ArrayList<Cookie> tmpCookies = null;
		ArrayList<Cookie> retCookies = null;
		
		switch (browser) {
		case 1:
			tmpCookies = chromeCookies;
			break;
			
		case 2:
			tmpCookies = firefoxCookies;
			break;
			
		case 3:
			tmpCookies = ieCookies;
			break;

		default:
			break;
		}
		
		if (tmpCookies != null) {
			retCookies = new ArrayList<>();
			
			for (Cookie cookie : tmpCookies) {
				if (cookie.getDomain().contains(domain)) {
					retCookies.add(cookie);
				}
			}
		}
		
		return retCookies;
	}

	/**
	 * gets chrome cookies list
	 * @return chrome cookie list
	 */
	public ArrayList<Cookie> getChromeCookies() {
		return chromeCookies;
	}

	/**
	 * gets firefox cookies list
	 * @return firefox cookie list
	 */
	public ArrayList<Cookie> getFirefoxCookies() {
		return firefoxCookies;
	}

	/**
	 * gets ie cookies list
	 * @return ie cookie list
	 */
	public ArrayList<Cookie> getIeCookies() {
		return ieCookies;
	}

	/**
	 * sets chrome cookie list
	 * @param chromeCookies returns list
	 */
	public void setChromeCookies(ArrayList<Cookie> chromeCookies) {
		this.chromeCookies = chromeCookies;
	}

	/**
	 * sets firefox cookie list
	 * @param firefoxCookies returns cookie list
	 */
	public void setFirefoxCookies(ArrayList<Cookie> firefoxCookies) {
		this.firefoxCookies = firefoxCookies;
	}

	/**
	 * sets ie cookie list
	 * @param ieCookies returns list
	 */
	public void setIeCookies(ArrayList<Cookie> ieCookies) {
		this.ieCookies = ieCookies;
	}
}
